package com.xh.clean.modular.system.controller;

import com.xh.clean.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.xh.clean.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.xh.clean.modular.system.model.UserOnline;
import com.xh.clean.modular.system.service.IUserOnlineService;

/**
 * 在线用户控制器
 *
 * @author yangjie
 * @Date 2018-10-18 22:22:06
 */
@Controller
@RequestMapping("/userOnline")
public class UserOnlineController extends BaseController {

    private String PREFIX = "/system/userOnline/";

    @Autowired
    private IUserOnlineService userOnlineService;

    /**
     * 跳转到在线用户首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "userOnline.html";
    }

    /**
     * 跳转到添加在线用户
     */
    @RequestMapping("/userOnline_add")
    public String userOnlineAdd() {
        return PREFIX + "userOnline_add.html";
    }

    /**
     * 跳转到修改在线用户
     */
    @RequestMapping("/userOnline_update/{userOnlineId}")
    public String userOnlineUpdate(@PathVariable Integer userOnlineId, Model model) {
        UserOnline userOnline = userOnlineService.selectById(userOnlineId);
        model.addAttribute("item",userOnline);
        LogObjectHolder.me().set(userOnline);
        return PREFIX + "userOnline_edit.html";
    }

    /**
     * 获取在线用户列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return userOnlineService.selectList(null);
    }

    /**
     * 新增在线用户
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UserOnline userOnline) {
        userOnlineService.insert(userOnline);
        return SUCCESS_TIP;
    }

    /**
     * 删除在线用户
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer userOnlineId) {
        userOnlineService.deleteById(userOnlineId);
        return SUCCESS_TIP;
    }

    /**
     * 修改在线用户
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UserOnline userOnline) {
        userOnlineService.updateById(userOnline);
        return SUCCESS_TIP;
    }

    /**
     * 在线用户详情
     */
    @RequestMapping(value = "/detail/{userOnlineId}")
    @ResponseBody
    public Object detail(@PathVariable("userOnlineId") Integer userOnlineId) {
        return userOnlineService.selectById(userOnlineId);
    }
}
